﻿using JobBack.Models;
using QG.JobBack.BLL.Service;
using QH.JobBack.Model;
using System;
using System.Web.Mvc;

namespace QG.JobBack.UI.Attributes
{
    /// <summary>
    /// 继承ActionFilterAttribute实现LogFilter日志
    /// </summary>
    public class LogFilter: ActionFilterAttribute
    {

        public LogFilter()
        {
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {

            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }

            object[] attrs = filterContext.ActionDescriptor.GetCustomAttributes(typeof(DescribeAttribute), false);
            if (attrs.Length > 0)
            {
                LogsService service=new LogsService();
                LogsInfo logs = new LogsInfo();
                logs.Operation = ((DescribeAttribute)attrs[0]).FunDescribe;
                logs.AdminId = 1;// AdminUserContext.context.UserInfo_no.AdminId;               
                logs.BeginTime = DateTime.Now;
                logs.EndTime = DateTime.Now;
                logs.Status = true;
                service.Add(logs);

            }
            base.OnActionExecuted(filterContext);
        }
    }
}